﻿
Public Class EntrySettings
    'Shared :
    Public Shared DefaultSettings As EntrySettings
    Shared Sub New()
        DefaultSettings = New EntrySettings
    End Sub
    'Ctor :
    Public Sub New()
        Me.Reset()
    End Sub
    'Fields :
    Public Property Method As Zip.CompressionMethod
    Public Property Level As Zlib.CompressionLevel
    Public Property Encryption As Zip.EncryptionAlgorithm
    Public Property Password As String
    Public Property Comment As String
    Public Property EmbedEntrySettingsInfos As Boolean
    'Routines :
    Public Sub Reset()
        Me.Method = Zip.CompressionMethod.Deflate
        Me.Level = Zlib.CompressionLevel.Default
        Me.Encryption = Zip.EncryptionAlgorithm.None
        Me.Password = Nothing
        Me.Comment = Nothing
        Me.EmbedEntrySettingsInfos = False
    End Sub
    Public Sub Reset(ByVal propertyname As String)
        Select Case propertyname
            Case "Method"
                Me.Method = Zip.CompressionMethod.Deflate
            Case "Level"
                Me.Level = Zlib.CompressionLevel.Default
            Case "Encryption"
                Me.Encryption = Zip.EncryptionAlgorithm.None
                Me.Password = Nothing
            Case "Comment"
                Me.Comment = Nothing
            Case "EmbedEntrySettingsInfos"
                Me.EmbedEntrySettingsInfos = False
        End Select
    End Sub
    Public Sub CopyFrom(ByVal entrysettings As EntrySettings)
        Me.Method = entrysettings.Method
        Me.Level = entrysettings.Level
        Me.Encryption = entrysettings.Encryption
        Me.Password = entrysettings.Password
        Me.Comment = entrysettings.Comment
        Me.EmbedEntrySettingsInfos = entrysettings.EmbedEntrySettingsInfos
    End Sub
    Public Function Infos() As String
        Dim sb As New System.Text.StringBuilder
        sb.AppendLine("(Entry Settings)")
        sb.AppendLine(Me.Method.InfosString)
        sb.AppendLine(Me.Level.InfosString)
        sb.AppendLine(Me.Encryption.InfosString)
        Return sb.ToString
    End Function
    Public Sub ApplyToZipEntry(ByVal zipentry As Zip.ZipEntry)
        zipentry.CompressionMethod = Me.Method
        zipentry.CompressionLevel = Me.Level
        zipentry.Encryption = Me.Encryption
        zipentry.Password = Me.Password
        If Me.EmbedEntrySettingsInfos = True Then
            zipentry.Comment = Me.Comment & vbNewLine & Me.Infos
        Else
            zipentry.Comment = Me.Comment
        End If
    End Sub
End Class